const Request={
  get(api){
    return new Promise(function(resolve,reject){
      wx.request({
        url: api,
        method: 'GET',
        dataType:'json',
        success:function(res){
        return resolve(res.data);
        },
        fail:function(res){
        return reject(res);
        }
      })
    });
  },
  postJson(api,data){
    return new Promise(function(resolve,reject){
      wx.request({
        url: api,
        method: 'POST',
        header:{'content-type':'application/json'},
        dataType:'json',
        data:JSON.stringify(data),
        success:function(res){
          return resolve(res.data);
        },
        fail:function(res){
          return reject(res);
        }
      })
    });
  },
  postForm(api,data){
    return new Promise(function(resolve,reject){
      wx.request({
        url: api,
        method: 'POST',
        header:{'content-type':'application/x-www-form-urlencoded'},
        dataType:'json',
        data:data,
        success:function(res){
          return resolve(res.data);
        },
        fail:function(res){
          return reject(res);
        }
      })
    });
  }
  ,
  put(api,data){
    return new Promise(function(resolve,reject){
      wx.request({
        url: api,
        method: 'PUT',
        header:{'content-type':'application/json'},
        dataType:'json',
        data:JSON.stringify(data),
        success:function(res){
          return resolve(res.data);
        },
        fail:function(res){
          return reject(res);
        }
      })
    });
  },
  delete(api){
    return new Promise(function(resolve,reject){
      wx.request({
        url: api,
        method: 'DELETE',
        dataType:'json',
        success:function(res){
        return resolve(res.data);
        },
        fail:function(res){
        return reject(res);
        }
      })
    });
  }
}

module.exports={
  Request
}